'''
rawsqli.py

Copyright 2009 Xavier Mendez Navarro aka Javi

This file is part of pysqlin

pysqlin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

pysqlin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with pysqlin; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
'''

import logging

from framework.settings import Settings
from framework.myexceptions import MyException
from framework.queries import Query
from framework.mymodel import InjectionData
from framework.interfaces import IPlugin
from framework.baseclass import BPlugin

class Rawsqli(BPlugin, IPlugin):
    def __init__(self, api):
	BPlugin.__init__(self, api)

	self.__logger = logging.getLogger('plugins.auxiliary.sql.rawsqli')

    def name(self): return "SQLi shell"
    def description(self): 
	return """
	Raw SQL Injection shell. 
	"""

    def init(self):
	pass

    def parameters(self): return {}

    def commands(self): 
	return (
	    ('run', 'Launchs raw sql injection shell.', 'run', [], self.cmd_raw),
	)

    def do_raw_query(self, query):
	for word in self.make_injection(Query(select=query)):
	    self.print_msg(word)

    def cmd_raw(self, **event):
	while True:
	    try:
		cmd = raw_input("shell> ")
		cmd = cmd.strip()
		if cmd: self.do_raw_query(cmd)
		print 
	    except Exception, error:
		self.print_error(error)
		break

def load(api):
    return Rawsqli(api)
